package main

import (
	"fmt"
	"reflect"
)

type Person2 struct {
	Name string `json:"NewName"`
	Age  int    `json:"NewAge"`
}

type newPerson struct {
	NewName string
	NewAge  int
}

func main() {
	t := Person2{
		Name: "小米",
		Age:  13,
	}

	refType := reflect.TypeOf(t)
	refValue := reflect.ValueOf(t)

	newPerson := &newPerson{}
	newValue := reflect.ValueOf(newPerson)

	for i := 0; i < refType.NumField(); i++ {
		field := refType.Field(i)
		newTag := field.Tag.Get("json")
		tValue := refValue.Field(i)
		newValue.Elem().FieldByName(newTag).Set(tValue)
	}

	fmt.Println(newPerson)
}
